package com.ddf.pluto.controller;

import com.alibaba.fastjson.JSON;
import com.ddf.publics.service.DueService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @program: dingding-financial
 * @description: 逾期控制层
 * @author: Mr.pluto
 * @create: 2020-06-30 20:09
 **/
@RequestMapping("/due")
@Controller
public class DueController {

    @Resource
    private DueService dueService;

    @RequestMapping("/dueJson")
    @ResponseBody
    public String dueJson(Integer limit,Integer page,Integer state,String realName){
        List<Map> list = dueService.quetyList(limit,(page-1)*limit,state,realName);
        list.forEach(map -> {
            Date date = new Date();
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date1 = new Date();
            try {
                date1 = simpleDateFormat.parse(map.get("d_time").toString());
            } catch (ParseException e) {
                e.printStackTrace();
            }

            Calendar calendar = Calendar.getInstance();
            calendar.setTime(date1);
            long timeInMillis1 = calendar.getTimeInMillis();
            calendar.setTime(date);
            long timeInMillis2 = calendar.getTimeInMillis();
            long betweenDays =  (timeInMillis2 - timeInMillis1) / (1000L*3600L*24L);

            map.put("dueday",betweenDays);
        });
        Map m = new HashMap();
        m.put("code",0);
        m.put("msg","");
        m.put("count",dueService.getListCount(state,realName));
        m.put("data",list);

        return JSON.toJSONString(m);
    }

    @RequestMapping("/toDueList")
    public String toDueList(){
        return "debit/backstage/dueList";
    }
}
